/*****************************************************************
                        CPU Scheduler
PURPOSE: This is the abstract base class for CPU scheduling. It uses the 
constructs of animation view to display trace simulation, statistics 
view  to display empirical data about the simulation, and input view to 
generate input for the algorithm.
*****************************************************************/
import java.util.ArrayList;

abstract public class Scheduler extends Object {
   ArrayList<Process> readyQueue, finishQueue, queue;
   int clock;
   Process P, T;
   boolean idle;
   public Thread thread;

   statsFrame st;
   animeFrame an;
   inputFrame in;

   /*--------------------------------------------------------
                        Constructor
   PURPOSE:  To ask help from views, set up data, and begin simulation
   PARAMTERS: references the input queue, stats and anime view. gets
   value of starting clock time.
   --------------------------------------------------------*/
   public Scheduler(ArrayList<Process> q, statsFrame s, animeFrame a, inputFrame i, int c) {
      queue = q;
      st = s;
      an = a;
      in = i;
      clock = c-1; // stagger for run loop
      idle = true;
      readyQueue = new ArrayList<Process>();
      finishQueue = new ArrayList<Process>();      
   } // constructor

   /*--------------------------------------------------------
                        Process Ready
   PURPOSE:  To determine if a process is ready
   PARAMTERS: gets the value of current clock time, returns ready process if any
   --------------------------------------------------------*/
   public Process processready(int tick) {
      for (int j=0; j<queue.size(); j++)
         if ((queue.get(j)).getArrival() <= tick)
            return queue.get(j);
      return null;
   } // clock

   /*--------------------------------------------------------
                        Reset Queues
   PURPOSE:  To reset all data structures for scheduling algorithms
   --------------------------------------------------------*/
   public void resetQueue() {
      readyQueue.clear();
      finishQueue.clear();
      queue.clear();
      in.resetGUI();
   } // reset all queues

} // Scheduler class
